﻿using UnityEngine;
using System.Collections;
using LitJson;
public class ActivityMenuLogic : SQMenuBase
{
    public Transform activityMenu;
    private string Path = "Client/UI640/";
    private ActivityData _activityListData;
    private float activityInitPosX = -280f;
    private float activityInitPosY = -48f;
    private float rowSpace = 282f;
    public override void OnClick(GameObject btn)
    {
        switch (btn.name)
        {
            case "btnActivityClose":
                btn.gameObject.GetComponent<UIPlaySound>().Play();
                UIManager.Instance.unpopMenu();
                break;
            default:
                break;
        }
    }
    public override void onStart()
    {
        base.onStart();
        activityData();
        initActivityView();
    }
    public void activityData()
    {
        _activityListData = JsonMapper.ToObject<ActivityData>(activityTestStr);

    }
    // 初始化显示
    public void initActivityView()
    {
        Object activityItemBg = Resources.Load(Path + "activityItemBg");
        Transform parentObj = activityMenu.transform.Find("ScrollView/Table").transform;
        int itemNumber = _activityListData.activity.Count;
        for (int j = 0; j < itemNumber; j++)
        {
            GameObject activityItemBG = (GameObject)Instantiate(activityItemBg);
            activityItemBG.name = "btnActivity" + j;
            //GameObject activityIcon = activityItemBG.FindChild("imgLandGold");
           // SetImgForObj(activityIcon.transform, Path + "ActivityMenu/imgExchargeGold");
            SparkExtensions.setParent(activityItemBG, parentObj.gameObject, (activityInitPosX + rowSpace * j), activityInitPosY);
            foreach (System.Reflection.PropertyInfo p in _activityListData.activity[j].GetType().GetProperties())
            {
                string childName = "txt_" + p.Name;
                string showTxt = p.GetValue(_activityListData.activity[j], null).ToString();
                SparkExtensions.SetChildText(activityItemBG, childName, showTxt);

            }

        }
    }







    private string activityTestStr = @"
{
    ""activity"": [
        {
            ""taskName"": ""每日对战"",
            ""taskPrice"": 1000,
            ""taskDes"": ""完成10局游戏""
        },
        {
            ""taskName"": ""购买月卡"",
            ""taskPrice"": 2000,
            ""taskDes"": ""购买vip月卡""
        },
        {
            ""taskName"": ""步步高升"",
            ""taskPrice"": 1000,
            ""taskDes"": ""在初级场完成3场胜利""
        },
       {
            ""taskName"": ""步步高升"",
            ""taskPrice"": 1000,
            ""taskDes"": ""在初级场完成3场胜利""
        },
        {
            ""taskName"": ""步步高升"",
            ""taskPrice"": 1000,
            ""taskDes"": ""在初级场完成3场胜利""
        }
    ]
}";

}
